public class MyQueue {
    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first = null;
    public ListNode last = null;
    public int usedSize = 0;

    public void offer(int val) {
        if(first == null){
            first = last = new ListNode(val);
            return;
        }
        ListNode cur = new ListNode(val);
        last.next = cur;
        cur.prev = last;
        last = cur;
    }
    public int poll() throws NullException{
        try{
            if(first == null){
                //抛异常
                throw new NullException("空");
            }

        }catch (NullException e){
            e.printStackTrace();
        }
        int val = first.val;
        if(first != last){
            first.next.prev = null;
        }
        first = first.next;
        return val;
    }
    public int peek() throws NullException{
        try{
            if(first == null){
                //抛异常
                throw new NullException("空");
            }

        }catch (NullException e){
            e.printStackTrace();
        }
        return first.val;
    }
    public boolean isEmpty() {
        if(first == null){
            return  true;
        }else {
            return false;
        }
    }

}
